home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 09, No. 05 (1988-05)(MicroSPARC)(Side A).zip / Nibble Volume 09, No. 05 (1988-05)(MicroSPARC)(Side A).po / COMMAND.SET.S < prev    next >
Text File  |  1996-12-24  |  13KB  |  518 lines

  1. ******************************************
  2. *                                        *
  3. *        C O M M A N D . S E T           *
  4. *            by Jon Hylands              *
  5. *         a ProDOS utility for           *
  6. *          adding some useful            *
  7. *          commands to the BI.           *
  8. *                                        *
  9. *          Copyright (C) 1988            *
  10. *           MicroSPARC, Inc              *
  11. *          Concord, MA 01742             *
  12. *                                        *
  13. ******************************************
  14. *     Merlin Pro Assembler, v2.34        *
  15. ******************************************
  16.  
  17. *   Zero Page Equates
  18.  
  19. length    = $2F
  20. cswl      = $36
  21. pcl       = $3A
  22. a1l       = $3C
  23. a2l       = $3E
  24. a4l       = $42
  25. index     = $5E
  26. txttab    = $67
  27. vartab    = $69
  28. strendh   = $6E
  29. himem     = $73
  30. ptr       = $FA
  31. name      = $FC
  32.  
  33. *  General System Equates
  34.  
  35. ibuf      = $200
  36. cursor    = $7FB
  37.  
  38. * ProDOS BI Global Page Equates
  39.  
  40. doscmd    = $BE03
  41. extrncmd  = $BE06
  42. errout    = $BE09
  43. printerr  = $BE0C
  44. errcode   = $BE0F
  45. vdosio    = $BE34
  46. xtrnaddr  = $BE50
  47. xcnum     = $BE53
  48. pbits     = $BE54
  49. spfxbuf   = $BEAD
  50. ssnmptr   = $BEB5
  51. getbufr   =  $BEF5
  52. bihimem   =  $BEFB
  53.  
  54. *  ProDOS System Global Page Equates
  55.  
  56. devadr32  = $BF26
  57. devlst    = $BF32
  58. bitmap    = $BF58
  59. level     = $BF94
  60. machid    = $BF98
  61. pfixptr   = $BF9A
  62.  
  63. *  Hardware Page Equates
  64.  
  65. rd80col   = $C01F
  66. spkr      = $C030
  67.  
  68. *  Applesoft ROM Equates
  69.  
  70. linkset   = $D4F2
  71.  
  72. *  Monitor ROM Equates
  73.  
  74. insds2    = $F88C
  75. pcadj     = $F953
  76. F8version = $FBB3 $06 if //e or //c
  77. IDbyte    = $FBC0 $00 if //c
  78. rdkey     = $FD0C
  79. crout     = $FD8E
  80. cout      = $FDED
  81. move      = $FE2C
  82. setv      = $FF58 known $60 to set V bit
  83. monitor   = $FF69
  84.  
  85. *  ProDOS MLI function call codes
  86.  
  87.  
  88.           org $2000
  89.  
  90. *   Relocator by Ken Manly
  91.  
  92.           lda #>last-begin+$100
  93.           jsr getbufr ask BASIC to reserve space
  94.           sta orig remember where it is
  95.           sta a1l
  96.           sec
  97.           sbc #>begin subtract present location
  98.           sta relo  to see how far program
  99.           lda #>last-begin+$100
  100.           sta a1l+1  will have to be moved
  101. protect   lda a1l Protect program space
  102.           jsr setbit  from ProDOS by setting
  103.           inc a1l  bits in the bitmap
  104.           dec a1l+1
  105.           bne protect
  106.  
  107.           lda himem+1 Make present HIMEM
  108.           sta bihimem  semi-permanent
  109.  
  110.           lda extrncmd+2 Link CMD into the
  111.           sta trynext+3  chain of external
  112.           lda extrncmd+1  commands, if any
  113.           sta trynext+2
  114.           lda orig If CMD cannot
  115.           sta extrncmd+2  recognize a command,
  116.           lda #0  it will pass control
  117.           sta extrncmd+1  to next routine
  118.  
  119.           lda #<begin To start relocation,
  120.           sta pcl  point program
  121.           lda #>begin  counter at beginning
  122.           sta pcl+1  of program
  123. fixloop   ldx #0
  124.           jsr insds2 Disassemble an opcode
  125.           lda (pcl),y Check opcode
  126.           beq fixadr BRK means end of code
  127.           ldy length Only 3-byte
  128.           cpy #2  instructions need
  129.           bne fx1  fixing
  130.           lda (pcl),y Only instructions
  131.           cmp #>begin  referring to addresses
  132.           blt fx1  within program
  133.           cmp #>last+$100 need fixing
  134.           bge fx1
  135.           clc  Fix by adding RELO
  136.           adc relo  offset to high byte
  137.           sta (pcl),y  of address
  138. fx1       jsr pcadj
  139.           sta pcl Move program counter
  140.           sty pcl+1  to next instruction
  141.           jmp fixloop
  142.  
  143. fxblp     clc  Add RELO offset to
  144.           adc relo  hi byte of each
  145.           sta atbl,y  address in the table
  146.           iny  Next address
  147. fixadr    iny
  148.           lda atbl,y 0 means end of
  149.           bne fxblp  table
  150.  
  151.           ldy #0 Move program to
  152.           sty a1l  the space reserved
  153.           lda #>begin  for it, using the
  154.           sta a1l+1  monitor MOVE routine
  155.           lda #<last
  156.           sta a2l
  157.           lda #>last
  158.           sta a2l+1
  159.           sty a4l
  160.           lda orig
  161.           sta a4l+1
  162.           jsr move
  163.  
  164.           ldy #0 Print greeting
  165. bnrlp     lda banner0,y
  166.           beq bnend
  167.           jsr cout
  168.           iny
  169.           bne bnrlp
  170. bnend     rts  Return to caller
  171.  
  172. setbit    pha  This subroutine protects
  173.           and #7  the memory page whose hi
  174.           tax   address byte is in (A)
  175.           pla
  176.           lsr a Upper five bits of (A)
  177.           lsr a  make an index into
  178.           lsr a  the bit map
  179.           tay
  180.           lda #0 Lower three bits of (A)
  181.           sec   choose the bit
  182. setlp     ror a  to be set -- (X) counts
  183.           dex   while bit is shifted
  184.           bpl setlp  from carry bit
  185.           ora bitmap,y
  186.           sta bitmap,y Set the bit in the bit map
  187.           rts
  188.  
  189. banner0   dfb $8D
  190.           asc "COMMAND.SET",8D
  191.           asc "A COMMAND UTILITY",8D
  192.           asc "COPYRIGHT (C) 1988",8D
  193.           asc "MICROSPARC, INC.",8D,8D
  194.           asc "COMMANDS : MON, BUZ, IRM, UNW, DIR",8D
  195.           asc "IIC-ONLY COMMANDS : CUR, BUF, DBF",8D,8D,00
  196.  
  197. orig      ds 1
  198. relo      ds 1
  199.  
  200.           ds \ (org $2200)
  201.  
  202. ********************************
  203.  
  204. begin     cld  identify to BI
  205.           ldx #0 pointer for command
  206. compr1    lda nametbl,x get low byte of command name address
  207.           sta name
  208.           lda nametbl+1,x get high byte of command name address
  209.           sta name+1
  210.           ldy #0
  211. compr     lda ibuf,y get byte from command
  212.           jsr upshift shift to upper case
  213.           cmp (name),y compare it to command name
  214.           bne notit get next command name
  215.           iny
  216.           cpy #3
  217.           blt compr check all three letters
  218.           bge found
  219.  
  220. notit     inx
  221.           inx
  222.           cpx cmdnum last command name ?
  223.           blt compr1 no, try next one
  224.  
  225. trynext   sec  indicate to BI command not found
  226.           jmp $0000 (old EXTCMD vector)
  227.  
  228. found     lda nameadr,x trick BI into calling routine directly
  229.           sta xtrnaddr
  230.           lda nameadr+1,x
  231.           sta xtrnaddr+1
  232.  
  233.           lda #0
  234.           sta pbits
  235.           sta pbits+1
  236.           sta xcnum
  237.           clc
  238.           rts
  239.  
  240. upshift   ora #$80 set high bit just in case
  241.           cmp #$FB
  242.           bge noshift special characters
  243.           cmp #$E1
  244.           blt noshift if not lower case
  245.           and #$DF clear case bit
  246. noshift   rts
  247.  
  248. ********************************
  249. *
  250. *  Commands for COMMAND.SET
  251. *
  252. ********************************
  253.  
  254.  
  255. cur        jsr  checkIIc  IIc?
  256.           bne  nocur   exit with message
  257.           lda #$9F (_)
  258.           sta cursor (poke 2043,159)
  259. curexit   clc
  260.           rts
  261. nocur     ldx #0
  262. cloop     lda IIcmsg,x
  263.           beq curexit
  264.           jsr cout
  265.           inx
  266.           bne cloop
  267.  
  268.  
  269. mon       jsr connect reconnect ProDOS manually
  270.           jmp monitor  and enter the monitor
  271.  
  272. ********************************
  273.  
  274. unw       cld
  275.           lda txttab
  276.           ldy txttab+1
  277.           sta index
  278.           sty index+1
  279.           ldy #1
  280.           tya
  281.           sta (index),Y
  282. unl1      ldy #4
  283. unl2      iny
  284.           lda (index),Y
  285.           bne unl2
  286.           iny
  287.           tya
  288.           clc
  289.           adc index
  290.           sta index
  291.           bcc unl3
  292.           inc index+1
  293. unl3      ldy #1
  294.           lda (index),Y
  295.           bne unl1
  296.           lda #3
  297.           clc
  298.           adc index
  299.           sta vartab
  300.           lda index+1
  301.           adc #0
  302.           sta vartab+1
  303.           jsr connect reconnect ProDOS manually
  304.           jsr linkset
  305.           rts
  306.  
  307. ********************************
  308.  
  309. connect   ldx #3 copy ProDOS I/O vectors back
  310. conloop   lda vdosio,x  to reconnect it
  311.           sta cswl,x
  312.           dex
  313.           bpl conloop
  314.           rts
  315.  
  316. ********************************
  317.  
  318. checkIIc  lda F8version check to see if we have an Apple //c
  319.           cmp #6
  320.           bne notIIc nope, so exit with zero flag clear
  321.           lda IDbyte we know it's a //e or a //c, so now
  322.                          ; see which one and set zero flag
  323.                          ; accordingly
  324. notIIc    rts            ; routine will exit with zero flag
  325.                          ; set if we have a //c, otherwise
  326.                          ; zero flag is clear
  327.  
  328. ********************************
  329.  
  330. ********************************
  331.  
  332. buf       jsr checkIIc see if we have a //c
  333.           bne nobuf nope, so don't try and hook it up
  334.  
  335.           sei            ; we do, so disable interrupts
  336.           lda #$80
  337.           sta $5FA buffer keystrokes without calling
  338.                          ; user's interrupt handler
  339.           sta $5FF set pointers for buffer
  340.           sta $6FF (where to store next keystroke and
  341.                          ; where the next will be read from)
  342.           lda $C0AA port 2 ACIA command register
  343.           ora #%00000001 turn it on by setting low bit
  344.           sta $C0AA so we can use printer as well
  345.           cli            ; enable interrupts
  346.           clc            ; carry must be clear on exit
  347.           rts
  348. nobuf     ldx #0
  349. nbloop    lda IIcmsg,x
  350.           beq nbexit
  351.           jsr cout
  352.           inx
  353.           bne nbloop
  354. nbexit    clc            ; carry must be clear on exit
  355.           rts
  356.  
  357. ********************************
  358.  
  359. dbf       jsr checkIIc see if //c once again
  360.           bne nobuf nope
  361.  
  362.           clc            ; carry must be clear
  363.           sei            ; yes, so disable interrupts
  364.           lda $C0AA get port 2 ACIA command register
  365.           and #%11111110 clear low bit to turn it off
  366.           sta $C0AA
  367.           cli  enable interrupts again
  368.           rts
  369.  
  370. ********************************
  371.  
  372. buz       jsr buzz2 buzz once
  373.           ldy #0
  374. buzz1     dey
  375.           bne buzz1 small delay
  376.           jsr buzz2 buzz again
  377.           rts
  378.  
  379. buzz2     lda #$10
  380.           sta buzztemp
  381.           ldx #$14
  382. bl1       bit spkr toggle speaker
  383. bl2       ldy #7
  384. bl3       dey
  385.           bne bl3
  386.           dex
  387.           bne bl2
  388.           dec buzztemp
  389.           bne bl1
  390.           rts
  391.  
  392. ********************************
  393.  
  394. dir       lda #0
  395.           sta errcode zero error code
  396.           lda rd80col see if 80-column hardware on
  397.           bpl noton
  398.           lda machid ProDOS machine id
  399.           and #%01000000 IIPlus ?
  400.           bne noton
  401.  
  402.           ldx #0 index for command
  403.           ldy #0 index for buffer
  404. dirl1     lda catalog,x get byte of command
  405.           beq dircont if end call command
  406.           sta ibuf,y store it in buffer
  407.           inx
  408.           iny
  409.           bne dirl1
  410.  
  411. dircont   jsr doscmd call ProDOS command handler
  412.           bcc dirend the carry flag is set if error
  413.           jsr printerr BI call to print the right err. message
  414. dirend    rts  and return
  415.  
  416. noton     ldx #9 index past "CATALOG" to "CAT"
  417.           ldy #0
  418.           beq dirl1 always
  419.  
  420. ********************************
  421.  
  422.  
  423. irm       lda $BF98      ; checking for aux memory
  424.           and #$30
  425.           cmp #$30
  426.           bne ramerr     ; no aux ram
  427.           lda $BF26      ; checking for slot 3, d2
  428.           cmp $BF16
  429.           beq ramerr
  430.           lda $BF27
  431.           cmp $BF17
  432.           beq ramerr
  433.           jmp irm0
  434. ramerr    ldx #0
  435. rloop     lda ramsg,x
  436.           beq rdone
  437.           jsr cout
  438.           inx
  439.           bne rloop
  440. rdone     rts
  441.  
  442. irm0      ldx #0
  443. irmloop   lda irmmsg,x get byte to print
  444.           beq irmcont end of message?
  445.           jsr cout print it
  446.           inx
  447.           bne irmloop
  448.  
  449. irmcont   jsr rdkey get keypress
  450.           jsr upshift must be upper case
  451.           cmp #"Y"
  452.           bne irmrts if no then return
  453.  
  454.           lda devlst
  455.           sta $43 device # is slot 3, drive 2
  456.           lda #3
  457.           sta $42 command is format
  458.           lda himem we need a 512 byte buffer
  459.           sta $44 use the BI's G.P. buffer
  460.           lda himem+1
  461.           sta $45
  462.           sta $C080 read RAM bank 2
  463.           jsr ramdrv format /RAM
  464.           sta $C081 back to ROM
  465. irmrts    rts  and return
  466.  
  467. ramdrv    jmp (devadr32) call handler
  468.  
  469. ********************************
  470.  
  471.           dfb 0 tells relocator that table follows
  472.  
  473. atbl      = * for relocater
  474.  
  475. *  The first set of addresses, nametbl, points to the command
  476. *  names in ASCII.
  477. *  The second set, nameadr, points to the actual routines.
  478. *  These addresses get relocated.
  479.  
  480. nametbl   da curn,monn,unwn,bufn,dbfn,buzn,dirn,irmn
  481. nameadr   da cur,mon,unw,buf,dbf,buz,dir,irm
  482.  
  483.           da $0000 end of relocated code
  484.  
  485. ********************************
  486.  
  487. *  Anything after this point does not get relocated.
  488.  
  489. cmdnum    dfb 16 number of commands*2
  490. curn      asc "CUR"
  491. monn      asc "MON"             please note that you also must
  492. unwn      asc "UNW"              update the number of commands in
  493. bufn      asc "BUF"              cmdnum if you add or subtract any.
  494. dbfn      asc "DBF"
  495. buzn      asc "BUZ"
  496. dirn      asc "DIR"
  497. irmn      asc "IRM"
  498.  
  499. buzztemp  dfb 0
  500.  
  501. catalog   asc "CATALOG",8D,00
  502.           asc "CAT",8D,00
  503.  
  504. irmmsg    dfb $8D
  505.           asc "FORMAT /RAM VOLUME ? (Y/N) ",00
  506.  
  507. IIcmsg    dfb $8D
  508.           asc "IIC ONLY!",00
  509.  
  510. ramsg     dfb $8D
  511.           asc "DEVICE NOT CONNECTED",00
  512.  
  513. last      = *
  514.           lst off
  515.           lst on
  516.           chk            ; generate checksum
  517.           lst off
  518.